package com.normalClasses.eye;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class Weather {
	private String city;
	private JSONObject message=new JSONObject();
	public JSONObject get_weather() {
		 String host = "https://jisutqybmf.market.alicloudapi.com";
		    String path = "/weather/query";
		    String method = "GET";
		    String appcode = "229aa18f4bd24852be4882bf2cc2c47d";
		    Map<String, String> headers = new HashMap<String, String>();
		    //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
		    headers.put("Authorization", "APPCODE " + appcode);
		    Map<String, String> querys = new HashMap<String, String>();
		    querys.put("city", city);
		    querys.put("citycode", "citycode");
		    querys.put("cityid", "cityid");
		    querys.put("ip", "ip");
		    querys.put("location", "location");
		    try {
		    	HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
		    	//获取response的body的json直接返回
		    	this.message=JSON.parseObject(EntityUtils.toString(response.getEntity()));
		    	//System.out.println(EntityUtils.toString(response.getEntity()));
		    } catch (Exception e) {
		    	e.printStackTrace();
		    	return null;
		    }
		    return message;
	 }
	public Weather(String city) {
		this.city=city;
	}
}
